#include "stdafx.h"
#include "list.h"
#include <stdlib.h>
#include <String>
#include <map>
#include <algorithm>
#include <iostream>
#include <math.h>

const double co = 7.0;

int hash(char* a)
{
	int res = 0;
	int t = strlen(a);
	while (t != 0)
	{
		
		res += *a * pow(co, t);
		a++;
		t --;
		
	}
	
	return res;
}

list add (list s, char* a)
{		
	list elem = (list)malloc(sizeof(listStruct));
	list elem3 = 0;
	list elem2 = s;
	elem->word = a;
	elem->count = 1;

	elem->next = 0;
	if (s != 0)
	{
	while(elem2 != 0)
	{
		elem3 = elem2;
		elem2 = elem2 ->next;
	}
	elem3->next = elem;

	}
	else 
	{
		s = elem;
	}
	return s;
}

list compare (list s, char *a)
{
	list look = s;
	bool b = false;
	while (look != 0)
	{
		if (strcmp (look->word, a) == 0)
		{
			look->count++;
			b = true;
			break;
		}
		look = look -> next;
	}
	if (!b)
	{
		s = add(s, a);
	}
	return s;
}

void print_list (list s)
{
	list output = s;	
	while(output != 0)
	{
		printf("%s : %d\n",output->word, output->count);
		output = output ->next;
	}
	
}